package com.ruoyi.consumer.utils.fill;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.consumer.controller.facilit.fill.BigDataItem;
import com.ruoyi.consumer.controller.facilit.fill.DataItem;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class JsonParserExample {

    public static List<DataItem> parseMinOrder(String jsonInput) {

        ObjectMapper mapper = new ObjectMapper();
        List<DataItem> dataList = null;
        try {
            // 解析整个JSON响应为Map
            Map<String, Object> responseMap = mapper.readValue(jsonInput, new TypeReference<Map<String, Object>>() {
            });

            // 从Map中获取datas字段并将其转换为DataItem对象的列表
            if (responseMap.containsKey("datas")) {
                dataList = mapper.convertValue(responseMap.get("datas"), new TypeReference<List<DataItem>>() {
                });
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return dataList;
    }

    public static BigDataItem parseBigOrder(String jsonInput ) {

        ObjectMapper mapper = new ObjectMapper();
        BigDataItem dataItem = null;
        try {
            // 解析整个JSON响应为Map
            Map<String, Object> responseMap = mapper.readValue(jsonInput, new TypeReference<Map<String, Object>>() {
            });

            // 从Map中获取datas字段并将其转换为DataItem对象
            if (responseMap.containsKey("datas")) {
                dataItem = mapper.convertValue(responseMap.get("datas"), BigDataItem.class);

                // 在这里处理dataItem
                System.out.println(dataItem);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return dataItem;
    }
}
